﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Configuration;

/// <summary>
/// Summary description for clbSendMail
/// </summary>
public static class clsBSSendMail
{
	
    public static bool sendMail(string[] to,string subject,string body)
    {
        try
        {
            Regex checkEmail = new Regex(@"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$");
            MailMessage message = new MailMessage();
            foreach (string item in to)
            {
                if (checkEmail.IsMatch(item))
                {
                    //message.From = new MailAddress("thiepcntt@gmail.com");
                    message.To.Add(new MailAddress(item));
                }
                else
                {
                    return false;
                }
             }
            message.Subject = subject;
            message.Body = body;
            message.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();
            client.EnableSsl = true;
            try
            {
                client.Send(message);
                return true;
            }
            catch (Exception)
            {
                return false;
            }  
        
        }
        catch (Exception)
        {
            
            throw;
        }
    }
}